package com.uzhie.media.bean;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext;

import java.io.Serializable;

/**
 * Created by TangFei on 2018/7/26.
 */
public class MediaMsgBean implements Serializable {

    private int msgID;
    private int bodyLength;
    private JSONObject msgBody;
    private ChannelHandlerContext channelHandlerContext;

    public int getMsgID() {
        return msgID;
    }

    /**
     * 获取16进制字符串格式的消息ID
     *
     * @return hex string
     */
    public String getHexMsgID() {
        byte[] bytes = new byte[2];
        bytes[0] = (byte) ((msgID >>> 8) & 0XFF);
        bytes[1] = (byte) (msgID & 0XFF);
        return ByteBufUtil.hexDump(bytes);
    }

    public void setMsgID(int msgID) {
        this.msgID = msgID;
    }

    public int getBodyLength() {
        return bodyLength;
    }

    public void setBodyLength(int bodyLength) {
        this.bodyLength = bodyLength;
    }

    public JSONObject getMsgBody() {
        return msgBody;
    }

    public void setMsgBody(JSONObject msgBody) {
        this.msgBody = msgBody;
    }

//    public JSONObject getSuccessBody() {
//        String result = "{\"code\": 200,\"msg\": \"请求成功\",\"result\": {\"data\": {}}}";
//        this.msgBody = JSON.parseObject(result);
//        return this.msgBody;
//    }


    public ChannelHandlerContext getChannelHandlerContext() {
        return channelHandlerContext;
    }

    public void setChannelHandlerContext(ChannelHandlerContext channelHandlerContext) {
        this.channelHandlerContext = channelHandlerContext;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this, false);
    }
}
